package command.webServices
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	
	import event.WebServiceEvent;
	
	import flash.events.Event;
	
	import model.Model;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	/**
	 * kvdsvsdl
	 */ 
	public class GetEventfulCommand implements ICommand, IResponder
	{
		
		private var model:Model = Model.instance;
		
		public function GetEventfulCommand()
		{
		}
		
		public function execute(evento:CairngormEvent):void
		{
			var location:String;
			var service:HTTPService = new HTTPService();
			service.method = "GET";
			service.resultFormat="e4x";
			
			if(evento.data.lat!=null)
				location= evento.data.lat + "," + evento.data.lng 
			else			
				location= "40.413496,-3.735352&date"
			//service.url = "http://api.eventful.com/rest/events/search?app_key=LWHHsLc84MdjzPXV&location=40.413496,-3.735352&date=Future&within=5";
			service.url = "http://api.eventful.com/rest/events/search?app_key=LWHHsLc84MdjzPXV&location="+location+"&date=Future&within=5";
			service.addEventListener(ResultEvent.RESULT, result);
			service.addEventListener(FaultEvent.FAULT, fault);
			service.send();
			
		}
		
		public function result(data:Object):void
		{
			
			var resultXML    : XML = XML(data.result);
			var resul_xml_list:XMLList = resultXML..event;			
			Model.instance.eventful_xml= resul_xml_list;
			//trace("Eventful-xml-list" + Model.instance.eventful_xml);
						
		}
		
		public function fault(info:Object):void
		{
			Alert.show("Fault");
			
		}
	}
}